package com.lktx.bbfactory.controller;

import com.lktx.bbfactory.common.CommonPage;
import com.lktx.bbfactory.common.CommonResult;
import com.lktx.bbfactory.common.gantt.*;
import com.lktx.bbfactory.entiy.DTO.GanttConfigDto;
import com.lktx.bbfactory.entiy.Product;
import com.lktx.bbfactory.service.productService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import com.lktx.bbfactory.entiy.VO.productListVo;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Resource
    private productService productService;

    //分页查询产品
    @GetMapping("/list")
    public CommonResult<CommonPage<productListVo>> list(@RequestParam(required = false) Integer projectId,
                                                  @RequestParam(required = false) String name,
                                                  @RequestParam(required = false) String type,
                                                  @RequestParam(required = false) String process,
                                                  @RequestParam String clientUsername,
                                                  @RequestParam Integer pageNum,
                                                  @RequestParam Integer pageSize) {
        CommonPage<productListVo> page = productService.listPage(projectId, name, type, process,clientUsername, pageNum, pageSize);
        return CommonResult.success(page);
    }

    //添加产品
    @PostMapping("/add")
    public CommonResult<String> addUser(@RequestBody Product product) {
        productService.addProduct(product);
        return CommonResult.success("添加成功");
    }

    //修改产品信息
    @PostMapping("/update")
    public CommonResult<String> updateUser(@RequestBody Product product) {
        productService.updateProduct(product);
        return CommonResult.success("更新成功");
    }

    @PostMapping("/delete")
    public CommonResult<String> deleteProduct(@RequestBody Map<String, Long> param) {
        Long id = param.get("id");
        boolean result = productService.removeById(id);
        return result ? CommonResult.success("删除成功") : CommonResult.failed("删除失败");
    }

    @PostMapping("/saveGanttConfig/{id}")
    public CommonResult<?> saveGanttConfig(@RequestBody List<GanttConfigDto> ganttConfigDtos, @PathVariable String id) {
       return productService.saveGanttConfig(id,ganttConfigDtos)?CommonResult.success("更新成功"):CommonResult.failed("更新失败");
    }


    @GetMapping("/ganttConfigTemplate")
    public CommonResult<?> ganttConfigTemplate(@RequestParam String projectType) {
        System.out.println(projectType);
        if(Objects.equals(projectType, "HIC")){
            return CommonResult.success(GanttStatusHic.getGanttTemplate());
        }
        if(Objects.equals(projectType, "电气")){
            return CommonResult.success(GanttStatusDq.getGanttTemplate());
        }
        if(Objects.equals(projectType, "高硅氧")){
            return CommonResult.success(GanttStatusGgy.getGanttTemplate());
        }
        if(Objects.equals(projectType, "力热")){
            return CommonResult.success(GanttStatusLr.getGanttTemplate());
        }
        if(Objects.equals(projectType, "结构复材")){
            return CommonResult.success(GanttStatusJgfc.getGanttTemplate());
        }
        if(Objects.equals(projectType, "涂层")){
            return CommonResult.success(GanttStatusTc.getGanttTemplate());
        }

      return null;
    }


}
